<template>
    <div class="app-container">
        <div class="SearchTop">
            <el-form :model="queryParams" ref="queryRef" :inline="true">
                <el-form-item label="标题：">
                    <el-input v-model="queryParams.title" placeholder="请输入标题" clearable @keyup.enter="handleQuery" />
                </el-form-item>
                <el-row class="searchBtn">
                    <el-col :span="8">
                        <el-form-item>
                            <el-button type="primary" icon="Search" @click="handleQuery"
                                v-hasPermi="['visualize:pageConfig:list']">查询
                            </el-button>
                            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
                        </el-form-item>
                    </el-col>
                    <el-col :span="5">
                        <el-form-item>
                            <el-button type="primary" plain icon="Plus" @click="handleAdd"
                                v-hasPermi="['visualize:pageConfig:add']">
                                新增
                            </el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <div class="tableList">
            <el-table :data="tableData" v-loading="loading" style="width: 100%" border class="table-container" stripe
                align="center">
                <el-table-column label="序号" width="60" type="index"> </el-table-column>
                <template v-for="(item, index) in tableHead" :key="index">
                    <el-table-column :prop="item.dataIndex" :label="item.title" :align="center" show-overflow-tooltip>

                    </el-table-column>
                </template>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template #default="scope">
                        <a @click="handleUpdate(scope.row)" title="编辑" v-hasPermi="['visualize:facilities:edit']">
                            <img src="../../../../assets/images/manage/bianji.png" alt="" />
                        </a>
                        <a @click="handleDelete(scope.row)" title="删除" v-hasPermi="['visualize:facilities:remove']">
                            <img src="../../../../assets/images/manage/shanchu.png" alt="" />
                        </a>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
                v-model:limit="queryParams.pageSize" @pagination="getList" />
        </div>
        <addPage ref="addFrom" @refresh="getList"></addPage>
    </div>
</template>
<script setup >
import addPage from "./addPage"
import { getPageConfig, delPageConfig } from '@/api/screen/facilities'
const { proxy } = getCurrentInstance();
const loading = ref(true);
const total = ref(0);
const data = reactive({
    form: {},
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: undefined,

    },
    tableHead: [
        {
            dataIndex: 'id',
            title: '主键id',

        },

        {
            dataIndex: 'title',
            title: '标题',

        },
        {
            dataIndex: 'showMode',
            title: '显示模式',

        },
        {
            dataIndex: 'sceneFacilities',
            title: '场景设施',

        },
        {
            dataIndex: 'detailApi',
            title: '详情接口',

        },
    ],
    tableData: []
});

const { queryParams, form, tableHead, tableData } = toRefs(data);
/** 查询列表 */
function getList() {
    loading.value = true;
    debugger
    getPageConfig(queryParams.value).then(response => {
        //  console.log('zuhu55555', response)
        if (response.code == 200) {
            tableData.value = response.rows
            total.value = response.total;
            loading.value = false;
        }
    })
}
getList();
/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}
/** 重置按钮操作 */
function resetQuery() {
    queryParams.value = {

    }
    proxy.resetForm("queryRef");
    handleQuery();
}
function handleAdd() {
    proxy.$refs["addFrom"].add();
}
function handleUpdate(row) {
    proxy.$refs["addFrom"].edit(JSON.parse(JSON.stringify(row)));
}
/** 删除按钮操作 */
function handleDelete(row) {
    const ids = row.id;
    proxy.$modal.confirm('是否确认删除此数据？').then(function () {
        return delPageConfig(ids);
    }).then(() => {
        getList();
        proxy.$modal.msgSuccess("删除成功");
    }).catch(() => { });
}
</script>
